package com.zjsru.oneDay;

/**
 * @Author: likew
 * @Date: 2022/2/23
 *
 * 仅仅反转字母
 *
 * 输入：s = "ab-cd"
 * 输出："dc-ba"
 *
 */
public class reverseOnlyLetters {
    public String reverseOnlyLetters(String s) {
        char[] c = s.toCharArray();
        int len = c.length;
        for (int i = 0,j = len - 1; i < j;) {
            while(!Character.isLetter(c[i]) && i < j){
                i++;
            }
            while(!Character.isLetter(c[j]) && i < j){
                j--;
            }
            if(i < j){
                char temp = c[i];
                c[i++] = c[j];
                c[j--] = temp;
            }
        }
        return String.valueOf(c);
    }
    

    public static void main(String[] args) {
        reverseOnlyLetters reverseOnlyLetters = new reverseOnlyLetters();
        String s = "ab-cd";
        System.out.println(reverseOnlyLetters.reverseOnlyLetters(s));
    }
}
